package health.lm.com.shop.presenter;

import health.lm.com.component_base.base.mvp.contract.XPresent;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.shop.activity.HLChatView;
import health.lm.com.shop.entity.HLChatResponse;
import health.lm.com.shop.model.MallModel;

/**
 * Created by Android Studio .
 * Project：hlian health.lm.com.shop.presenter
 * Date：2019/8/9 18:16
 * Introduce：私信、私信记录
 */
public class HLChatPresenter extends XPresent<HLChatView> {

    /**
     * 历史记录数据
     */
    public void getHistoryData(String id, int page, int pageSize) {
        MallModel.getInstance().getChatHistory(id, page, pageSize, new SimpleCallBack<HLChatResponse>() {
            @Override
            public void onSuccess(HLChatResponse pHLChatResponse) {
                if (hasV()) getV().setNewData(pHLChatResponse.getChat_list());
            }
        });
        //List<HLChatEntity> chatEntities = new ArrayList<>();
        //for (int a = 0; a < 15; a++) {
        //    HLChatEntity chatEntity = new HLChatEntity();
        //    chatEntity.setAvatar("http://image109.360doc.com/DownloadImg/2018/03/1008/126782666_1_2018031008485635.jpeg");
        //    chatEntity.setType(a % 2 == 0 ? "1" : "2");
        //    chatEntity.setMsg("你好啊~~~~" + a);
        //    chatEntity.setTime("2019-08-09 :15:" + a);
        //    chatEntities.add(chatEntity);
        //}
        //if (hasV()) getV().setNewData(chatEntities);
    }

    public void getData(String id) {
        MallModel.getInstance().getChatingList(id, new SimpleCallBack<HLChatResponse>() {
            @Override
            public void onSuccess(HLChatResponse pHLChatResponse) {
                if (hasV()) getV().setNewData(pHLChatResponse.getChat_list());
            }
        });
        //List<HLChatEntity> chatEntities = new ArrayList<>();
        //for (int a = 0; a < 15; a++) {
        //    HLChatEntity chatEntity = new HLChatEntity();
        //    chatEntity.setAvatar("http://image109.360doc.com/DownloadImg/2018/03/1008/126782666_1_2018031008485635.jpeg");
        //    chatEntity.setType(a % 2 == 0 ? "1" : "2");
        //    chatEntity.setMsg("你好啊~~~~" + a);
        //    chatEntity.setTime("2019-08-09 :15:" + a);
        //    chatEntities.add(chatEntity);
        //}
        //if (hasV()) getV().setNewData(chatEntities);
    }

    /**
     * 发送信息
     *
     * @param id      对话对方会员ID
     * @param content 对话内容
     */
    public void submitContetn(String id, String content) {
        MallModel.getInstance().getChatSubmit(id, content, new SimpleCallBack<Object>() {
            @Override
            public void onSuccess(Object pO) {
                getData(id);
            }
        });
    }
}
